package com.sky;

import com.sky.common.config.CacheConstants;
import com.sky.common.config.Config;
import com.sky.common.utils.IpUtil;
import com.sky.common.utils.NVRClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@Slf4j
@EnableCaching
@EnableScheduling
@EnableAsync
@SpringBootApplication(exclude = {RedisAutoConfiguration.class})
public class SkyApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SkyApplication.class);
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SkyApplication.class, args);
        for(String arg:args){
            if("--enable-nvr".equals(arg)){
                Config.nvrEnable = true;
            }
        }

        //初始化NVR动态链接库
        if(Config.nvrEnable) {
            NVRClientUtil.init();
        }

        String hostIp = IpUtil.getHostIp();
        String port = context.getEnvironment().getProperty("server.port");
        log.info("Swagger访问地址：http://{}:{}/doc.html", hostIp, port);
    }

}
